/* eslint-disable no-eval */

import Mock from 'mockjs'
import { result, getNowTime, mockPageRes, qsparse } from '../util'
// 仓库数据
const mockWarehouseList = (params) => result(() => {
  const totalList = []
  const w1 = { warehouseName: '深圳仓库1', warehouseCode: 'W00001', address: '深圳市龙华区100号', status: 1, createTime: getNowTime(), updateTime: getNowTime() }
  const w2 = { warehouseName: '深圳仓库2', warehouseCode: 'W00002', address: '深圳市龙华区99号', status: 0, createTime: getNowTime(), updateTime: getNowTime() }
  totalList.push(w1, w2)
  return mockPageRes(params, totalList)
})

const mockProductStorageList = (params) => result(() => {
  const totalList = []
  const p0 = { productName: '滚珠丝杆1', productCode: 'P0001', productModel: 'M0001', warehouseCode: 'W00001', warehouseName: '深圳仓库1', stockTotal: 100, availableNum: 80, lockedNum: 20, thresholdNum: 30 }
  const p1 = { productName: 'LGD导轨2', productCode: 'P0002', productModel: 'M0001', warehouseCode: 'W00001', warehouseName: '深圳仓库1', stockTotal: 78, availableNum: 50, lockedNum: 28, thresholdNum: 40 }
  totalList.push(p0, p1)
  return mockPageRes(params, totalList)
})

// 产品库存数据
const mockProductEntryList = (params) => result(() => {
  const totalList = []
  const p0 = { productName: '滚珠丝杆1', productCode: 'P0001', productModel: 'M0001', warehouseCode: 'W00001', warehouseName: '深圳仓库1', count: 10, price: 12.89, dataTime: getNowTime(), operator: '王力' }
  const p1 = { productName: 'LGD导轨2', productCode: 'P0002', productModel: 'M0021', warehouseCode: 'W00001', warehouseName: '深圳仓库1', count: 89, price: 22.81, dataTime: getNowTime(), operator: '王力' }
  const p2 = { productName: 'LGD导轨3', productCode: 'P0003', productModel: 'M0022', warehouseCode: 'W00001', warehouseName: '深圳仓库1', count: 60, price: 32.81, dataTime: getNowTime(), operator: '王力' }
  const p3 = { productName: '滚珠丝杆4', productCode: 'P0004', productModel: 'M0024', warehouseCode: 'W00001', warehouseName: '深圳仓库1', count: 22, price: 21.81, dataTime: getNowTime(), operator: '王力' }
  const p4 = { productName: '滚珠丝杆5', productCode: 'P0005', productModel: 'M0024', warehouseCode: 'W00001', warehouseName: '深圳仓库1', count: 19, price: 11.81, dataTime: getNowTime(), operator: '王力' }
  const p6 = { productName: '滚珠丝杆6', productCode: 'P0005', productModel: 'M0024', warehouseCode: 'W00001', warehouseName: '深圳仓库1', count: 19, price: 11.81, dataTime: getNowTime(), operator: '王力' }
  const p7 = { productName: '滚珠丝杆7', productCode: 'P0005', productModel: 'M0024', warehouseCode: 'W00001', warehouseName: '深圳仓库1', count: 19, price: 11.81, dataTime: getNowTime(), operator: '王力' }
  const p8 = { productName: '滚珠丝杆8', productCode: 'P0005', productModel: 'M0024', warehouseCode: 'W00001', warehouseName: '深圳仓库1', count: 19, price: 11.81, dataTime: getNowTime(), operator: '王力' }
  const p9 = { productName: '滚珠丝杆9', productCode: 'P0005', productModel: 'M0024', warehouseCode: 'W00001', warehouseName: '深圳仓库1', count: 19, price: 11.81, dataTime: getNowTime(), operator: '王力' }
  const p10 = { productName: '滚珠丝杆10', productCode: 'P0005', productModel: 'M0024', warehouseCode: 'W00001', warehouseName: '深圳仓库1', count: 19, price: 11.81, dataTime: getNowTime(), operator: '王力' }
  const p11 = { productName: '滚珠丝杆11', productCode: 'P0005', productModel: 'M0024', warehouseCode: 'W00001', warehouseName: '深圳仓库1', count: 19, price: 11.81, dataTime: getNowTime(), operator: '王力' }
  const p12 = { productName: '滚珠丝杆12', productCode: 'P0005', productModel: 'M0024', warehouseCode: 'W00001', warehouseName: '深圳仓库1', count: 19, price: 11.81, dataTime: getNowTime(), operator: '王力' }
  totalList.push(p0, p1, p2, p3, p4, p6, p7, p8, p9, p10, p11, p12)
  return mockPageRes(params, totalList)
})
const mockEntryProductRecord = (params) => result(() => {
  const warehouseName = ['深圳仓库1', '深圳仓库2']
  const tag = ['导轨', '滚珠丝杆', '机床丝杆']
  const list = Mock.mock({
    'Array|1-10': [{
      'productName': '@ctitle',
      'productTag|1': tag,
      'productCode': /P[0-9]{7}/,
      'productModel': /M[A-Z]{2}[0-9]{5}/,
      'warehouseCode': /W[0-9]{7}/,
      'warehouseName|1': warehouseName,
      'enteredNum': '@integer(10, 100)',
      'notEntryNum': '@integer(10, 100)',
      'entryDateTime': '@datetime',
      'operator': '@cname'
    }]
  })
  return list.Array
})
export default {
  'post|/api/stock/getWarehouseList': (option) => {
    const params = qsparse(option.body)
    return mockWarehouseList(params)
  },
  'post|/api/stock/getProductStorageList': (option) => {
    const params = qsparse(option.body)
    return mockProductStorageList(params)
  },
  'post|/api/stock/getProductEntryList': (option) => {
    const params = qsparse(option.body)
    return mockProductEntryList(params)
  },
  'post|/api/stock/getProductOutList': (option) => {
    const params = qsparse(option.body)
    return mockProductEntryList(params)
  },
  'post|/api/stock/getEntryProductRecordList': (option) => {
    const params = qsparse(option.body)
    return mockEntryProductRecord(params)
  }
}

